<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <h3>这是注册页面</h3>
    用户名：<input type="text" id="username"><span></span><br>
    密码：<input type="text" id="password"><span></span><br>
    <input type="button" value="注册" id="btn">
    <a href="./login.html">去登录</a>
</body>
<script>

    $("#btn").onclick = function(){
        let str = "username="+$("#username").value+"&password="+$("#password").value;
        const xhr = new XMLHttpRequest();
        xhr.open("post", "http://localhost:3000/register");
        xhr.onload = function(){
            if(xhr.status === 200){
                console.log(xhr.responseText)
            }
        }
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.send(str);
    }



    function $(sel){
        return document.querySelector(sel);
    }

</script>
</html>